package com.meepo.feed.message

import android.os.Bundle
import android.view.View
import com.meepo.basic.router.RouterManager
import com.meepo.basic.components.listfragment.ListFragmentParams
import com.meepo.basic.components.view.MeepoFragment
import com.meepo.basic.schema.Enums
import com.meepo.basic.schema.user.User
import com.meepo.feed.R
import com.meepo.feed.action.ActionListFragment
import kotlinx.android.synthetic.main.message_fragment.*

class MessageFragment : MeepoFragment() {

//    private lateinit var fragment: ActionListFragment

    override fun refreshOnVisible(): Boolean = true

    override fun initView(view: View, savedInstanceState: Bundle?) {

//        StatusBarHelper.immerse(this.requireActivity(), header_cl)

        val fragment = RouterManager.FeedModule.routeToActionList(
            itemType = Enums.ITEM_TYPE_ITEM,
            targetUserId = User.SELF,
            listFragmentParams = ListFragmentParams(enablePullRefresh = false)
        ) as ActionListFragment

        loadRootFragment(R.id.action_list_frame, fragment)

        refresh_layout.setEnableLoadMore(false)
        refresh_layout.setReboundDuration(1000)
        refresh_layout.setOnRefreshListener {

//            fragment.refresh()

            refresh_layout.finishRefresh(1000)
//            val fragment = ActionListFragment()
//            this.replaceChildFragment(R.id.action_list_frame, fragment)
        }


        at_it.setOnClickListener {
            RouterManager.FeedModule.routeToMessage(requireContext(), 0)
        }

        new_fans_it.setOnClickListener {
            RouterManager.FeedModule.routeToMessage(requireContext(), 1)
        }

        sys_notify_it.setOnClickListener {
            RouterManager.FeedModule.routeToMessage(requireContext(), 2)
        }


    }

    override fun initData() {
//        fragment.refresh()
        // todo
//        refresh_layout.finishRefresh()
    }

    override fun setUpContentLayout(): Int = R.layout.message_fragment

    companion object {
        private var shortVideoFragment: MessageFragment? = null
        fun instance(): MessageFragment {
            if (shortVideoFragment == null) {
                shortVideoFragment = MessageFragment()
            }
            return shortVideoFragment!!
        }
    }
}